package com.sky.mapper;

import com.sky.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface UserMapper {

    @Select("select * from sky_take_out.user where openid = #{openid}")
    User getByOpenid(String openid);

    /**
     * 插入数据
     * @param user
     */
    void insert(User user);

    /**
     * 根据id查询用户
     * @param userId
     * @return
     */
    @Select("select * from sky_take_out.user where id = #{id}")
    User getById(Long userId);

    /**
     * 根据创建时间查询用户
     * @param beginTime
     * @param endTime
     * @return
     */
    List<User> getByCreateTime(LocalDateTime beginTime, LocalDateTime endTime);

    /**
     * 根据截止时间统计用户数量
     * @param beginTime
     * @return
     */
    @Select("select count(0) from sky_take_out.user where create_time < #{beginTime}")
    Integer getBydateline(LocalDateTime beginTime);

    /**
     * 根据动态条件统计用户数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
